package com.zyx.concurrentdemo.mytest.c02;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.FutureTask;

/**
 * @author Yaxi.Zhang
 * @since 2021/10/12 11:18
 */
@Slf4j(topic = "c.FutureTaskDemo")
public class FutureTaskDemo {

    public static void main(String[] args) throws Exception {
        FutureTask<Integer> f = new FutureTask<>(() -> {
            log.debug("Hello");
            Thread.sleep(3000);
            return 1;
        });

        Thread t = new Thread(f, "future");

        t.start();

        log.debug("before");

        // 阻塞主线程
        Integer res = f.get();

        // log.debug("result =====>>>>> {}", res);
        log.debug("after");

    }
}
